import request from '../utils/request'
import type { Conversation, Message, Notification } from '@/types/message'

export const messageApi = {
    // 获取会话列表
    getConversations() {
        return request.get<Conversation[]>('/messages/conversations')
    },

    // 获取特定会话的消息
    getMessages(conversationId: string) {
        return request.get<Message[]>(`/messages/conversations/${conversationId}`)
    },

    // 发送消息
    sendMessage(conversationId: string, content: string) {
        return request.post<Message>(`/messages/conversations/${conversationId}`, { content })
    },

    // 标记会话已读
    markConversationAsRead(conversationId: string) {
        return request.put(`/messages/conversations/${conversationId}/read`)
    },

    // 获取通知列表
    getNotifications() {
        return request.get<Notification[]>('/messages/notifications')
    },

    // 标记通知已读
    markNotificationAsRead(notificationId: string) {
        return request.put(`/messages/notifications/${notificationId}/read`)
    },

    // 标记所有通知已读
    markAllNotificationsAsRead() {
        return request.put('/messages/notifications/read-all')
    },

    // 获取未读消息和通知数量
    getUnreadCounts() {
        return request.get<{ conversations: number, notifications: number }>('/messages/unread-counts')
    },

    // 创建新会话
    createConversation(receiverId: string, initialMessage: string) {
        return request.post<Conversation>('/messages/conversations', {
            receiverId,
            initialMessage
        })
    }
} 